package com.xcc.xccdiff;

import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.io.File;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    public static final String FileDir = File.separator + "xccdiff";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                new MyThread(MainActivity.this).start();
            }
        });

//        findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
//            public void onClick(View v) {
//                OptionsPickerView pickerView = new OptionsPickerView
//                        .Builder(MainActivity.this, new OptionsPickerView.OnOptionsSelectListener() {
//                    public void onOptionsSelect(int options1, int options2, int options3, View v) {
//                        String s = list.get(options1);
//                        Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
//                    }
//                }).build();
//                pickerView.setPicker(list);
//                pickerView.show();
//            }
//        });
//        list = new ArrayList<>();
//        list.add("xcc");
//        list.add("rookieCi");
//        list.add("帅");
    }

    private List<String> list;

    public static String getSDCard() {//+ File.separator
        return Environment.getExternalStorageDirectory().getPath();
    }

    public static class MyThread extends Thread {
        public MyThread(Context context) {
            this.context = context;
        }

        private Context context;

        public void run() {
            String s = getSDCard() + FileDir;
            File file = new File(s);
            if (!file.exists()) file.mkdir();
            String apkFilePath = Bzip2.getApkFilePath(context, context.getPackageName());
            boolean b = new Bzip2().xccDiff(apkFilePath, s + File.separator + "newXcc.apk"
                    //new Bzip2().xccDiff(s + File.separator + "app-debug_old.apk", s + File.separator + "newXcc.apk"
                    , s + File.separator + "path.apk");
            System.out.println("合并结果:" + b);
        }
    }
}
